<?php
namespace Home\Controller;
use Home\Model\MesModel;
use Home\Model\VipModel;

class IndexController extends CommonController  {

    public function index(){
        if(IS_POST){
            if(trim(empty(i('post.mes')))){
                $this->error('请输入内容');
            }
            $data = [
                'mes_message'=>i('post.mes'),
                'mes_time'=>time(),
            ];
            (new MesModel())->add($data);
        }
        $mes = (new MesModel())->order('mes_time desc')->select();
        $this->assign('mes',$mes);
        $num = (new VipModel())->count();
        $this->assign('num',$num);
        $this->display();
    }

    public function del()
    {
        $id = i('get.id');
        (new MesModel())->where(['mes_id'=>$id])->delete();
        $this->redirect('Index/index');
    }

    public function out(){
        session_unset();
        session_destroy();
        $this->success('退出成功',u('Login/index'));
    }
}